class Budget {
  constructor(id, user_id, category_id, amount, period, start_date, end_date, created_at) {
    this.id = id;
    this.user_id = user_id;
    this.category_id = category_id;
    this.amount = parseFloat(amount);  // Ensure amount is a number
    this.period = period;
    this.start_date = start_date;
    this.end_date = end_date;
    this.created_at = created_at;
  }

  // Create a Budget instance from a database row
  static fromRow(row) {
    return new Budget(
      row.id,
      row.user_id,
      row.category_id,
      row.amount,
      row.period,
      row.start_date,
      row.end_date,
      row.created_at
    );
  }

  // Convert Budget instance to JSON
  toJSON() {
    return {
      id: this.id,
      user_id: this.user_id,
      category_id: this.category_id,
      amount: this.amount,  // This will be a number
      period: this.period,
      start_date: this.start_date,
      end_date: this.end_date,
      created_at: this.created_at
    };
  }
}

module.exports = Budget;